import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import math from "./plugin/math";
import ShopsUtil from "./plugin/shops";
import Icon from "@/components/Iconfont.vue";
import Popups from "@/components/Popups";
import ElementUI from "element-ui";
import "./theme/theme/index.css";

Vue.config.productionTip = false;
Vue.component("icon", Icon);

Vue.prototype.$math = math;
Vue.prototype.Popups = Popups;
Vue.use(ElementUI);
Vue.use(ShopsUtil);

let pages = [];
router.options.routes.forEach((item) => {
  if (item.children) {
    item.children.forEach((sub) => {
      if (sub.children) {
        sub.children.forEach((_sub) => {
          let _page = {};
          _page.name = _sub.name;
          _page.title = _sub.meta.title;
          pages.push(_page);
        });
      } else {
        let _page = {};
        _page.name = sub.name;
        _page.title = sub.meta.title;
        pages.push(_page);
      }
    });
  } else {
    let _page = {};
    _page.name = item.name;
    _page.title = item.meta.title;
    pages.push(_page);
  }
});

Vue.prototype.pages = pages;

Vue.prototype.initialize = function () {
  this.$store.dispatch("car/init");
  // this.$store.dispatch("user/check");
};

new Vue({
  router,
  store,
  render: (h) => h(App),
  watch: {
    $route: function () {
      let list = document.getElementsByClassName("mouse-cover-canvas");
      for (let i = 0; i < list.length; i++) {
        document.body.removeChild(list[i]);
      }
    },
  },
  created() {
    this.initialize();
  },
}).$mount("#app");
